package com.demo.aop.after.simple;

import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.framework.ProxyFactory;

import java.lang.reflect.Method;

/**
 * 描述：后置通知无法改变返回值，但是可以进行异常的抛出
 *
 * @author lida
 * @time 2019/10/23 9:46
 */
public class SimpleAfterReturningAdvice implements AfterReturningAdvice {
	public static void main(String[] args) {
		Pianist target = new Pianist();

		//创建代理工厂
		ProxyFactory pf = new ProxyFactory();
		pf.addAdvice(new SimpleAfterReturningAdvice());
		pf.setTarget(target);

		//获得代理后的对象
		Pianist proxy = (Pianist)pf.getProxy();
		System.out.println(proxy.speak());
	}

	@Override
	public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
		System.out.println("After Method: method's name---" + method.getName());
	}
}
